﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace TestImport.Model.DatabaseRepositories
{
    public abstract partial class DatabaseRepository
    {
        /************/
        /* Levering */
        /************/

        public DataTable Levering_GetData()
        {
            return defaultExecuteReaderDataTable(CommandType.Text, "SELECT leveringID, datumLevering, isPlato, opmerking, leveringNaam, status FROM Levering");
        }

        public DataTable Levering_GetMaxLeveringID()
        {
            return defaultExecuteReaderDataTable(CommandType.Text, "SELECT MAX(leveringID) AS maxLeveringID FROM Levering");
        }

        public void Levering_InsertLevering(DateTime datumLevering, bool isPlato, string leveringNaam, string opmerking, bool status)
        {
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(5);
                dbManager.AddParameters(0, "@datumLevering", datumLevering);
                dbManager.AddParameters(1, "@isPlato", isPlato);
                dbManager.AddParameters(2, "@leveringNaam", leveringNaam);
                dbManager.AddParameters(3, "@opmerking", opmerking);
                dbManager.AddParameters(4, "@status", status);
                dbManager.ExecuteNonQuery(CommandType.Text, "INSERT INTO Levering (datumLevering, isPlato,leveringNaam, opmerking, status) VALUES (@datumLevering, @isPlato, @leveringNaam, @opmerking, @status)");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                dbManager.Dispose();
            }
        }

        public bool Levering_Truncate()
        {
            bool succeed = false;
            try
            {
                dbManager.Open();
                dbManager.ExecuteNonQuery(CommandType.Text, "TRUNCATE TABLE Levering");
                succeed = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                dbManager.Dispose();
            }
            return succeed;
        }

    }
}
